<?php

namespace app\shopapi\model\wx;

use app\shopapi\model\Shop;
use fast\Http;
use think\Model;


//微信支付商户进件
class WechatpayApply extends Model
{

    //开户银行
    public function bank()
    {
        $data = [
            '工商银行','交通银行','招商银行','民生银行','中信银行','浦发银行','兴业银行','光大银行','广发银行','平安银行','北京银行','华夏银行','农业银行'
            ,'建设银行','邮政储蓄银行','中国银行','宁波银行'
        ];
        return $data;
    }

    //特约商户进件（提交申请单）
    public function apply($shop_id)
    {
        $shop_info = Shop::get($shop_id);

        $api = "https://api.mch.weixin.qq.com/v3/applyment4sub/applyment/";

        if ($shop_info['subject_type']==1||$shop_info['subject_type']==2){
            //个人
            $subject_type = 'SUBJECT_TYPE_INDIVIDUAL';
            $bank_account_type = 'BANK_ACCOUNT_TYPE_PERSONA';
            $account_name = $shop_info['realname'];
            //$settlement_id = '719';
        } else {
            //企业
            $subject_type = 'SUBJECT_TYPE_ENTERPRISE';
            $bank_account_type = 'BANK_ACCOUNT_TYPE_CORPORATE';
            $account_name = $shop_info['shop_name'];
        }

        $body = [
            'business_code'=>'',//业务申请编号
            'contact_info'=>[
                //超级管理员信息
                'contact_type'=>'LEGAL',//超级管理员类型
                'contact_name'=>$shop_info['realname'],//超级管理员姓名
                'contact_id_doc_type'=>'IDENTIFICATION_TYPE_IDCARD',//超级管理员证件类型
                'contact_id_number'=>$shop_info['id_card_num'],//超级管理员身份证件号码
                'contact_id_doc_copy'=>$shop_info['front_id_card_img'],//超级管理员证件正面照片
                'contact_id_doc_copy_back'=>$shop_info['reverse_id_card_img'],//超级管理员证件反面照片
                'contact_period_begin'=>$shop_info['id_card_start_time'],//超级管理员证件有效期开始时间
                'contact_period_end'=>$shop_info['id_card_end_time'],//超级管理员证件有效期结束时间
                'mobile_phone'=>$shop_info['mobile'],//联系手机
                'contact_email'=>$shop_info['email'],//联系邮箱
            ],
            'subject_info'=>[
                //主体资料
                'subject_type'=>$subject_type,//主体类型
                'business_license_info'=>[
                    'license_copy'=>$shop_info['business_license_img'],//营业执照照片
                    'license_number'=>$shop_info['business_license_num'],//注册号/统一社会信用代码
                    'merchant_name'=>$shop_info['shop_name'],//商户名称
                    'legal_person'=>$shop_info['id_card_name'],//个体户经营者/法人姓名
                    'license_address'=>$shop_info['address'],//注册地址
                ],//营业执照
                'business_info'=>[
                    'merchant_shortname'=>$shop_info['shop_name'],//商户简称
                    'service_phone'=>$shop_info['mobile'],//客服电话
                    'sales_info'=>[
                        'sales_scenes_type'=>"SALES_SCENES_STORE",//经营场景类型
                    ],//经营场景
                ],//经营资料
                'settlement_info'=>[
                    'settlement_id'=>"719",//入驻结算规则ID
                    'qualification_type'=>"休闲娱乐",//所属行业
                ],//结算规则
                'bank_account_info'=>[
                    'bank_account_type'=>$bank_account_type,//账户类型
                    'account_name'=>$account_name,//开户名称
                    'account_bank'=>$shop_info['bank_name'],//开户银行
                    'bank_address_code'=>$shop_info['bank_address_code'],//开户银行省市编码
                    'bank_name'=>$shop_info['bank'],//开户银行全称（含支行）
                    "account_number"=>$shop_info['bank_num'],//银行账号
                ],//结算账户
            ]
        ];

        $res = Http::sendRequest($api,$body);

        dump($res);die;
    }
}